Skip to content

test: add overflow tests for MutableBuffer#9958

Merged
alamb merged 2 commits into
apache:mainfrom
SoimanVasile:buffer-overflow-tests
Jun 2, 2026
Merged

test: add overflow tests for MutableBuffer#9958
alamb merged 2 commits into
apache:mainfrom
SoimanVasile:buffer-overflow-tests

Conversation

@SoimanVasile
Copy link
Copy Markdown
Contributor

Description

While analyzing the memory allocation logic in MutableBuffer, I identified that the with_capacity and reserve methods correctly use .expect() guards to prevent integer overflows.

However, I couldnt find test cases for this .expect() guard in the current test suite. This PR adds 2 #[should_panic] tests in mutable.rs to verify that the API correctly panics
Changes:

  • Added test_mutable_new_capacity_overflow to cover MutableBuffer::new
  • Added test_mutable_reserve_overflow to cover MutableBuffer::reserve

Rationale

Adding these tests ensures that the safety guards in arrow-buffer remain intact and provides explicit coverage for edge cases involving near-usize::MAX allocations.

Tests

  • test_mutable_new_capacity_overflow
  • test_mutable_reserve_overflow

@github-actions github-actions Bot added the arrow Changes to the arrow crate label May 10, 2026
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thank you @SoimanVasile 🙏

@alamb
Copy link
Copy Markdown
Contributor

alamb commented Jun 2, 2026

I merged up to hopefully get a clean CI run

@alamb alamb merged commit 870fb06 into apache:main Jun 2, 2026
26 checks passed
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Jun 2, 2026

Thanks again @SoimanVasile

@SoimanVasile
Copy link
Copy Markdown
Contributor Author

@alamb Thanks so much for the review and the merge! I'm relatively new to open-source contributing, but I really enjoyed diving into the MutableBuffer logic here.
​I'd love to keep the momentum going and pick up another issue. Since I'm still getting familiar with the codebase, are there any other buffer-related tickets, or perhaps some low-level memory optimization issues you'd recommend I look at next?

@alamb
Copy link
Copy Markdown
Contributor

alamb commented Jun 2, 2026

Thanks @SoimanVasile -- I don't know of any small tickets yet. Maybe you could help by looking at some of the PRs that are outstanding / looking for review and help.

PRs that are small and focused are the ones that we are likely to be able to review quickly

Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Jun 2, 2026
### Description
While analyzing the memory allocation logic in `MutableBuffer`, I
identified that the `with_capacity` and `reserve` methods correctly use
`.expect()` guards to prevent integer overflows.

However, I couldnt find test cases for this `.expect()` guard in the
current test suite. This PR adds 2 `#[should_panic]` tests in
`mutable.rs` to verify that the API correctly panics
**Changes:**
* Added `test_mutable_new_capacity_overflow` to cover
`MutableBuffer::new`
* Added `test_mutable_reserve_overflow` to cover
`MutableBuffer::reserve`

###  Rationale
Adding these tests ensures that the safety guards in `arrow-buffer`
remain intact and provides explicit coverage for edge cases involving
near-`usize::MAX` allocations.

### Tests
-  `test_mutable_new_capacity_overflow`
- `test_mutable_reserve_overflow`

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@SoimanVasile
Copy link
Copy Markdown
Contributor Author

@alamb Sounds good! I will definitely look into the outstanding PRs next week when I have a bit more time to focus on them. Thanks for the guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants